
# 直接写参数规则 和用模型定义规则，还是稍有不同的，用模型看起来更紧凑一点: BaseModel Field
# 和 Query Path Body 类似，Field 也有同样的参数

from typing import Annotated, Literal

from fastapi import FastAPI, Query
from pydantic import BaseModel, Field

app = FastAPI()


class FilterParams(BaseModel):
    model_config = {"extra": "forbid"} # 不能查模型外的参数，可能会更安全一点吧

    limit: int = Field(100, gt=0, le=100)
    offset: int = Field(0, ge=0)
    order_by: Literal["created_at", "updated_at"] = "created_at"
    tags: list[str] = []


@app.get("/items/")
async def read_items(filter_query: Annotated[FilterParams, Query()]):
    return filter_query
